package com.example.ioc.service.impl;


import com.example.ioc.dao.UserDao;
import com.example.ioc.dao.UserDao2;
import com.example.ioc.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 该来通过@service注解声明，需要自动组装bean实例，
 * 可当前来有两个有参数的构造函数
 * ides编辑器提示：Class doesn't contain matching constructor for autowiring
 * Spring容器在自动组装bean实例时，找不多合适的构造函数
 */
@Service
public class UserServiceImpl implements UserService {

    private UserDao userDao;

    @Autowired
    public void setUserDao(UserDao userDao){
        this.userDao = userDao;
    }

    @Resource
    private UserDao2 userDao2;

    public UserServiceImpl(@Autowired UserDao userDao){
        this.userDao = userDao;
    }

    @Autowired
    public UserServiceImpl(UserDao userDao, UserDao2 userDao2) {
        this.userDao = userDao;
        this.userDao2 = userDao2;
    }

    @Override
    public void getUserName() {
        System.out.println(userDao);
        userDao.getUserName();
    }
}
